//
//  FenLeiDetailZongheView.m
//  Experss
//
//  Created by Chen on 2017/8/1.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "FenLeiDetailZongheView.h"

@interface FenLeiDetailZongheView ()<UITableViewDelegate,UITableViewDataSource>

/**  */
@property (nonatomic , strong) NSArray *titleArray;

/**  */
@property (nonatomic , strong) UITableView *tableView;

@end

@implementation FenLeiDetailZongheView


+ (instancetype)initWithFenLeiDetailZongheView{
    FenLeiDetailZongheView *view = [[self alloc] initWithFrame:CGRectMake(0, 40, kScreen_Width, kScreen_Height-40-64)];
    return view;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        self.titleArray = @[@"综合",@"最新",@"最热"];
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 120, SCREEN_WIDTH, kScreen_Height-40-64-120)];
        view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    
        [view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeFromSuperview)]];
        [self addSubview:view];
        
        [self createSubViews];
    }
    return self;
}

- (void)setSelectString:(NSString *)selectString{
    _selectString = selectString;
    
    [self.tableView reloadData];
}

- (void)createSubViews{
    
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, self.titleArray.count*40) style:(UITableViewStyleGrouped)];
    tableView.backgroundColor = [UIColor whiteColor];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.rowHeight = 40;
    tableView.bounces = NO;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.showsHorizontalScrollIndicator = NO;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
//    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:tableView];
    
    self.tableView = tableView;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    NSString *titleString = self.titleArray[indexPath.row];
    
    
    if ([titleString isEqualToString:self.selectString]) {
        cell.textLabel.textColor = RGBAColor(0, 149, 250, 1);
    } else {
        cell.textLabel.textColor = [UIColor blackColor];
    }
    
    cell.textLabel.text = titleString;
    
    cell.textLabel.frame = CGRectMake(50, 0, 200, 40);
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([self.delegate respondsToSelector:@selector(selectTypeWithString:)]) {
        [self.delegate selectTypeWithString:self.titleArray[indexPath.row]];
    }
    
    
    [self removeFromSuperview];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
